// 保存棋盘格子
import { ecs } from '../framework/assets/libs/ecs/ECS';
import { GridModelComponent } from "./gridModelComponent";
import { ListenComponent } from "./listenComponent";
import {
    AudioEliminateComponent,
    AudioMatchComponent,
    GridCheckComponent,
    GridFillSpaceComponent
} from "./utilsComponent";

@ecs.register('GridEntity')
export class GridEntity extends ecs.Entity {
    // model名要跟GridModelComponent 注册的名字一致，才能自动挂载
    GridModel!: GridModelComponent;

    protected init() {
        // 添加组件
        this.add(GridModelComponent);
        this.add(ListenComponent);
        // 初始化 model
        this.GridModel.init();
    }

    // 检查 grid
    allowCheckGrid() {
        this.add(GridCheckComponent);
    }

    // 监听用户
    allowListen() {
        this.GridModel.cleanCell();
        this.add(ListenComponent);
    }

    // 填充空格
    fillGrid() {
        this.add(GridFillSpaceComponent);
    }

    playEliminate(step: number) {
        const comp = this.add(AudioEliminateComponent);
        comp.step = step;
    }

    // 连续匹配的音效
    playContinuousMatch(step: number) {
        const comp = this.add(AudioMatchComponent);
        comp.step = step;
    }

}
